﻿@model SnsLite.SnsUser
@if (!string.IsNullOrEmpty(Model.Account))
{
    if (Model.IsLogin && Model.IsCurrent)
    {
        <link href="~/static/vendor/cropper/cropper.min.css" rel="stylesheet" />
        <link href="~/static/css/sitelogo.css" rel="stylesheet" />
    }
    <div class="text-center">
        <div id="crop-avatar">
            <img id="avatar" class="img-circle" alt="SnsLite" src="@Url.ToLogoUrl(Model.Avatar)" style="width:150px;height:150px;border:1px solid #ccc;padding:2px;" />
        </div>
        <h3 id="compName" class="text-uppercase">@Model.Name</h3>
    </div>
    <div class="container-fluid counts">
        <div class="row">
            <div class="col-xs-4 col-md-4 text-center line" style="padding:5px 0;">
                分享<br />@Model.ShareCount
            </div>
            <div class="col-xs-4 col-md-4 text-center line" style="padding:5px 0;">
                关注<br />@Model.AttentionCount
            </div>
            <div class="col-xs-4 col-md-4 text-center" style="padding:5px 0;">
                粉丝<br />@Model.FansCount
            </div>
        </div>
    </div>
    if (Model.IsLogin)
    {
        if (Model.IsCurrent)
        {
            <script type="text/javascript">
                $('#avatar').hover(
                    function () {
                        $(this).removeClass('btn-default').addClass('btn-primary').attr('title', '修改公司LOGO');
                    },
                    function () {
                        $(this).removeClass('btn-primary').addClass('btn-default').removeAttr('title');
                    }
                );
            </script>
            <script src="~/static/vendor/cropper/cropper.min.js"></script>
            <script src="~/static/js/sitelogo.js"></script>
            <div class="modal fade" id="avatar-modal" aria-hidden="true" aria-labelledby="avatar-modal-label" role="dialog" tabindex="-1">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <form class="avatar-form" action="@Url.Action("ChangeAvatar", "Home")" enctype="multipart/form-data" method="post">
                            <div class="modal-header">
                                <button class="close" data-dismiss="modal" type="button">&times;</button>
                                <h4 class="modal-title" id="avatar-modal-label">修改公司LOGO</h4>
                            </div>
                            <div class="modal-body">
                                <div class="avatar-body">
                                    <div class="avatar-upload">
                                        <input class="avatar-src" name="avatar_src" type="hidden">
                                        <input class="avatar-data" name="avatar_data" type="hidden">
                                        <label for="avatarInput">图片上传</label>
                                        <input class="avatar-input" id="avatarInput" name="avatar_file" type="file">
                                    </div>
                                    <div class="row">
                                        <div class="col-md-9">
                                            <div class="avatar-wrapper"></div>
                                        </div>
                                        <div class="col-md-3">
                                            <div class="avatar-preview preview-lg"></div>
                                            <div class="avatar-preview preview-md"></div>
                                            <div class="avatar-preview preview-sm"></div>
                                        </div>
                                    </div>
                                    <div class="row avatar-btns">
                                        <div class="col-md-9">
                                            <div class="btn-group">
                                                <button class="btn" data-method="rotate" data-option="-90" type="button" title="左转90度"><i class="fa fa-undo"></i> 向左旋转</button>
                                            </div>
                                            <div class="btn-group">
                                                <button class="btn" data-method="rotate" data-option="90" type="button" title="右转90度"><i class="fa fa-repeat"></i> 向右旋转</button>
                                            </div>
                                        </div>
                                        <div class="col-md-3">
                                            <button class="btn btn-success btn-block avatar-save" type="submit"><i class="fa fa-save"></i> 保存修改</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

            <div class="loading" aria-label="Loading" role="img" tabindex="-1"></div>
        }
        else
        {
            <div class="row" style="margin-top:20px;">
                <div class="col-xs-6 col-md-6 text-center" style="padding-right:5px;">
                    @if (Model.IsCurrentFriend)
                    {
                        <button type="button" class="btn btn-default" id="btnFriend" style="width:100px;">
                            <i class="glyphicon glyphicon-ok"></i> 公司好友
                        </button>
                        <script type="text/javascript">
                            $('#btnFriend').hover(
                                function () {
                                    $(this).removeClass('btn-default').addClass('btn-primary')
                                           .html('<i class="glyphicon glyphicon-minus"></i> 删除好友')
                                           .bind('click', function () {
                                               if (confirm('确定删除好友？')) {
                                                   $.post('@Url.ToAjax(AjaxRequestType.Relation_RemoveFriend)', {
                                                       param: JSON.stringify(['@Model.Id'])
                                                   }, function (data) {
                                                       Message.handle(data, function () { location = location; });
                                                   });
                                               }
                                           });
                                },
                                function () {
                                    $(this).removeClass('btn-primary').addClass('btn-default')
                                           .html('<i class="glyphicon glyphicon-ok"></i> 公司好友')
                                           .unbind('click');
                                }
                            );
                        </script>
                    }
                    else if (Model.IsCurrentValidate)
                    {
                        <button type="button" class="btn btn-default" disabled="disabled" style="width:100px;">
                            <i class="glyphicon glyphicon-check"></i> 好友验证
                        </button>
                    }
                    else
                    {
                        <button type="button" class="btn btn-primary" style="width:100px;" onclick="addFriend()">
                            <i class="glyphicon glyphicon-plus"></i> 加好友
                        </button>
                        <script type="text/javascript">
                            function addFriend() {
                                $.post('@Url.ToAjax(AjaxRequestType.Relation_AddFriend)', {
                                    param: JSON.stringify(['@Model.Id'])
                                }, function (data) {
                                    Message.handle(data, function () { location = location; });
                                });
                            }
                        </script>
                    }
                </div>
                <div class="col-xs-6 col-md-6 text-center" style="padding-left:5px;">
                    @if (Model.IsMutualAttention)
                    {
                        <button type="button" class="btn btn-default" id="btnAttention" style="width:100px;">
                            <i class="glyphicon glyphicon-ok"></i> 互相关注
                        </button>
                        <script type="text/javascript">
                            $('#btnAttention').hover(
                                function () {
                                    $(this).removeClass('btn-default').addClass('btn-primary')
                                           .html('<i class="glyphicon glyphicon-minus"></i> 取消关注')
                                           .bind('click', function () {
                                               $.post('@Url.ToAjax(AjaxRequestType.Relation_RemoveAttention)', {
                                                   param: JSON.stringify(['@Model.Id'])
                                               }, function (data) {
                                                   Message.handle(data, function () { location = location; });
                                               });
                                           });
                                },
                                function () {
                                    $(this).removeClass('btn-primary').addClass('btn-default')
                                           .html('<i class="glyphicon glyphicon-ok"></i> 互相关注')
                                           .unbind('click');
                                }
                            );
                        </script>
                    }
                    else if (Model.IsCurrentAttention)
                    {
                        <button type="button" class="btn btn-default" id="btnAttention" style="width:100px;">
                            <i class="glyphicon glyphicon-ok"></i> 已关注
                        </button>
                        <script type="text/javascript">
                            $('#btnAttention').hover(
                                function () {
                                    $(this).removeClass('btn-default').addClass('btn-primary')
                                           .html('<i class="glyphicon glyphicon-minus"></i> 取消关注')
                                           .bind('click', function () {
                                               $.post('@Url.ToAjax(AjaxRequestType.Relation_RemoveAttention)', {
                                                   param: JSON.stringify(['@Model.Id'])
                                               }, function (data) {
                                                   Message.handle(data, function () { location = location; });
                                               });
                                           });
                                },
                                function () {
                                    $(this).removeClass('btn-primary').addClass('btn-default')
                                           .html('<i class="glyphicon glyphicon-ok"></i> 已关注')
                                           .unbind('click');
                                }
                            );
                        </script>
                    }
                    else
                    {
                        <button type="button" class="btn btn-primary" style="width:100px;" onclick="addAttention()">
                            <i class="glyphicon glyphicon-heart-empty"></i> 关注
                        </button>
                        <script type="text/javascript">
                            function addAttention() {
                                $.post('@Url.ToAjax(AjaxRequestType.Relation_AddAttention)', {
                                    param: JSON.stringify(['@Model.Id'])
                                }, function (data) {
                                    Message.handle(data, function () { location = location; });
                                });
                            }
                        </script>
                    }
                </div>
            </div>
        }
    }
}
else
{
    <div class="text-center">
        <img class="img-circle" alt="SnsLite" src="~/static/img/logo.png" style="width:150px;height:150px;border:1px solid #ccc;padding:2px;" />
        <p style="margin-top:10px;">
            <i class="glyphicon glyphicon-exclamation-sign text-danger"></i>您还未登录，请<a href="@Url.ToAction("Index", "Home")">登录</a>或<a href="@Url.ToAction("Index", "Home")">注册</a>！
        </p>
    </div>
}